﻿(function () {

    // Creating a variable that will hold the InfoWindow object
    var infowindow;

    window.onload = function () {

        // Creating an object literal containing the properties 
        // we want to pass to the map  
        var options = {
            zoom: 3,
            center: new google.maps.LatLng(37.09024, 102.392578),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        // Creating the map  
        var map = new google.maps.Map(document.getElementById('map'), options);

        // Creating a LatLngBounds object
        var bounds = new google.maps.LatLngBounds();

        // Creating an array that will contain the coordinates 
        // for New York, San Francisco, and Seattle
        var places = [];
        places.push(new google.maps.LatLng(39.93396, 116.408386));
        places.push(new google.maps.LatLng(31.290287, 121.464844));
        places.push(new google.maps.LatLng(23.160563, 113.264923));
        places.push(new google.maps.LatLng(29.57704, 106.550217));

        var notes = [];
        notes.push({ name: '北京', desp: '首都' });
        notes.push({ name: '上海', desp: '金融中心' });
        notes.push({ name: '广州', desp: '南方大城市' });
        notes.push({ name: '重庆', desp: '直辖市' });

        // Creating a variable that will hold 
        // the InfoWindow object
        var infowindow;

        // Looping through the places array
        for (var i = 0; i < places.length; i++) {

            // Adding the markers
            markOption.position = places[i];
            markOption.map = map;
            markOption.title = 'city' + i;
            markOption.icon = '/Images/pirate.png';
            var marker = ZEUS.GMAP.markOnMap();

            // Wrapping the event listener inside an anonymous function 
            // that we immediately invoke and passes the variable i to.
            (function (i, marker) {
                var infoHtml = '<div class="info">'
                    + notes[i].name + '<br />'
                    + notes[i].desp
                    + '</div>';
                ZEUS.GMAP.msgBox(map, marker, infoHtml);
            })(i, marker);

            // Extending the bounds object with each LatLng
            bounds.extend(places[i]);

        }

        // Adjusting the map to new bounding box
        map.fitBounds(bounds)

    };

})();